package com.microservice.salmon.oauth.service.impl;

import com.microservice.salmon.db.mapper.SysMenuMapper;
import com.microservice.salmon.oauth.service.MenuService;
import com.salmon.common.tree.ITree;
import com.salmon.common.tree.TreeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 菜单操作相关服务层
 * </p>
 *
 * @author 王洪庆 2019-01-03 10:26
 */
@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private SysMenuMapper sysMenuMapper;

    /**
     * 查询树形菜单，当有孩子节点的时候才进行缓存
     * @param loginName 用户登录名称
     * @return
     */
    @Override
    @Cacheable(cacheNames = "menu_info_tree", key = "#loginName", unless = "#result.children == null || #result.children.size() == 0")
    public ITree obtainMenuTreeByLoginName(String loginName) {
        return TreeUtils.getTree(sysMenuMapper.getMenuInfoByLoginName(loginName));
    }
}
